package com.jd.order.service.impl;

import com.jd.order.domain.OrderPetAcquisition;
import com.jd.order.domain.OrderProduct;
import com.jd.order.service.IOrderProductService;
import com.jd.basic.service.impl.BaseServiceImpl;
import com.jd.pet.domain.Pet;
import com.jd.pet.domain.SearchMasterMsg;
import com.jd.pet.dto.ConfirmDto;
import com.jd.product.domain.Product;
import com.jd.product.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jd
 * @since 2023-03-18
 */
@Service
public class OrderProductServiceImpl extends BaseServiceImpl<OrderProduct> implements IOrderProductService {

    /**
     * 取消订单
     * @author kabuda
     * @date 2023/3/17 23:07

     */
    @Autowired
    private ProductMapper productMapper;

    @Override
    @Transactional
    public void cancel(Long id) {
        // 修改服务单为取消
        OrderProduct order = super.findById(id);
        if (null != order) {
            order.setState(-1);
            super.update(order);
        }
        // 删除服务信息
        productMapper.delete(order.getProductId());

    }

    @Override
    public void confirm(ConfirmDto dto) {
        // 1 修改收购单状态为已完成
        OrderProduct order = super.findById(dto.getId());
        order.setState(1);
        order.setPrice(dto.getMoney());
        super.update(order);
        //  修改服务信息
        Product product = new Product();
        product.setCostprice(dto.getMoney());
        productMapper.update(product);
    }
}
